package tpo.vista.empleados;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import tpo.controlador.Sistema;
import tpo.to.ClienteDTO;
import tpo.to.TipoModeloDTO;


public class BajaCliente extends JFrame {
	private Sistema sistema;
	final JFrame jframe = this;
	
	public BajaCliente(Sistema sistema){
		super("Baja Cliente");
		this.sistema = sistema;
		init();
		setVisible(true);
	}
	
	private void init(){
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLayout(new GridBagLayout());
		GridBagConstraints gc = new GridBagConstraints();
		
		List<ClienteDTO> clientesTO = sistema.getClientesDTO();

		JLabel labelCliente = new JLabel ("Cliente");
		final JComboBox clientesCombo = new JComboBox(clientesTO.toArray());
		JButton button = new JButton("Eliminar");
		
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evento) {
				try {
			        ClienteDTO c = (ClienteDTO) clientesCombo.getSelectedItem();
					sistema.eliminarCliente(c.getCodigo());
					dispose();
					System.out.println("Operacion realizada");
				} catch (Exception e) {
					System.out.println("Error al eliminar cliente");
				}
			}
		});
		
		gc.gridx = 0;	// Columna
		gc.gridy = 0;	// Fila
		add(labelCliente, gc);		
		gc.gridx = 1;
		gc.gridy = 0;
		add(clientesCombo, gc);
		
		gc.gridx = 0;
		gc.gridy = 1;
		add(button, gc);

		pack();
		setSize(400, 300);
	}

}
